import {defineStore} from "pinia";
import {ref} from "vue";

interface UserData {
    id?: number;
    username?: string;
    password?: string;
    nickname?: string;
    avatar?: string;
    profile?: string;
    tags?: string[];
    phone?: string;
    email?: string;
    longitude?: number;
    latitude?: number;
    role?: string;
    points?: number;
    postCount?: number;
    postTotalView?: number;
    likeCount?: number;
    collectCount?: number;
    followCount?: number;
    fanCount?: number;
    createTime?: string;

}

export const useUserStore = defineStore('HomieHatchUser', () => {
        const id = ref();
        const username = ref("");
        const nickname = ref("");
        const avatar = ref("");
        const profile = ref("");
        const tags = ref<string[]>([]);
        const phone = ref("");
        const email = ref("");
        const longitude = ref();
        const latitude = ref();
        const role = ref("");
        const points = ref();
        const postCount = ref();
        const postTotalView = ref();
        const likeCount = ref();
        const collectCount = ref();
        const followCount = ref();
        const fanCount = ref();
        const createTime = ref("");


        const setUserInfo = (userData: UserData) => {
            if (userData.id !== undefined) id.value = userData.id;
            if (userData.username !== undefined) username.value = userData.username;
            if (userData.nickname !== undefined) nickname.value = userData.nickname;
            if (userData.avatar !== undefined) avatar.value = userData.avatar;
            if (userData.profile !== undefined) profile.value = userData.profile;
            if (userData.tags !== undefined) tags.value = userData.tags;
            if (userData.phone !== undefined) phone.value = userData.phone;
            if (userData.email !== undefined) email.value = userData.email;
            if (userData.longitude !== undefined) longitude.value = userData.longitude;
            if (userData.latitude !== undefined) latitude.value = userData.latitude;
            if (userData.role !== undefined) role.value = userData.role;
            if (userData.points !== undefined) points.value = userData.points;
            if (userData.postCount !== undefined) postCount.value = userData.postCount;
            if (userData.postTotalView !== undefined) postTotalView.value = userData.postTotalView;
            if (userData.likeCount !== undefined) likeCount.value = userData.likeCount;
            if (userData.collectCount !== undefined) collectCount.value = userData.collectCount;
            if (userData.followCount !== undefined) followCount.value = userData.followCount;
            if (userData.fanCount !== undefined) fanCount.value = userData.fanCount;
            if (userData.createTime !== undefined) createTime.value = userData.createTime;
        };

        return {
            id,
            username,
            nickname,
            avatar,
            profile,
            tags,
            phone,
            email,
            longitude,
            latitude,
            role,
            points,
            postCount,
            postTotalView,
            likeCount,
            collectCount,
            followCount,
            fanCount,
            createTime,
            setUserInfo
        };
    },
    {
        persist: true,
    },
)
